'''
自助取款机
1.用户信息数据源

功能
2.查看余额
3.存钱
4.取钱
5.退出

交互界面
7.用户名登陆
8.密码验证
9.账户操作
'''

#1.用户信息数据源
user_list = [
    {'name':'zhangsan','password':'333333','money':3000},
    {'name':'lisi','password':'444444','money':4000},
    {'name':'wangwu','password':'555555','money':5000}]

#2.查看余额
def show_account_info(user_name):
    for user in user_list:
        if user['name'] == user_name:
            print('你的账户余额：{}元'.format(user['money']))
            print('='*20)

#3.存钱
def deposit_money(user_name,add_num):
    for user in user_list:
        if user['name'] == user_name:
            user['money'] += add_num
            print('+++本次存款金额：{}元'.format(add_num))

#4.取钱
def withdraw_money(user_name,min_num):
    for user in user_list:
        if user['name'] == user_name:
            if user['money'] >= min_num:
                user['money'] -= min_num
                print('---本次取款金额：{}元'.format(min_num))
            else:
                print('余额不足')


#5.退出系统
def loginOut():
    pass

#交互界面

#6.用户名登陆
while True:
    input_name = input('请输入用户名：')
    flag1 = False
    for user in user_list:
        if user['name'] == input_name:
            flag1 = True
    if flag1 == True:
        break
    else:
        print('用户不存在，请先注册账号')

#密码验证
while True:
    input_password = input('请输入密码：')
    flag2 = False
    for user in user_list:
        if user['name'] == input_name:
            if user['password'] == input_password:
                print('密码正确，验证成功')
                flag2 = True
    if flag2 == True:
        break
    else:
        print('密码错误，请重试')

#账户操作
while True:
    # 输出初始操作界面
    print('=' * 8, '账户管理', '=' * 8)
    print('{:1}{:9}{:10}'.format(' ', '1.查看余额', '2.存款'))
    print('{:1}{:9}{:10}'.format(' ', '3.取款', '4.退出系统'))
    print('=' * 20)
    key = input('请输入对应操作选项')

    #根据输入值，执行对应操作
    if key == '1':
        print('='* 8,'查看余额','='* 8)
        show_account_info(input_name)
        input('按回车继续')

    elif key == '2':
        print('=' * 9, '存款', '=' * 9)
        add_money = int(input('请输入存款金额：'))
        deposit_money(input_name, add_money)
        show_account_info(input_name)
        input('按回车继续')

    elif key == '3':
        print('=' * 9, '取款', '=' * 9)
        min_money = int(input('请输入取款金额：'))
        withdraw_money(input_name, min_money)
        show_account_info(input_name)
        input('按回车继续')

    elif key == '4':
        loginOut()
        print('='*9,'再见','='*9)
        break

    else:
        print('=' * 8, '操作无效', '=' * 8)
